<?
	$name = isset($moduleSettings['items']['title']) ? $item[$moduleSettings['items']['title']] : $item['name'];
	$name = strip_tags($name);
	$name = strlen($name) > 30 ? substr($name, 0, 25) . '...' : $name;
?>
<h1>Edit item</h1>
<?=Html::anchor((isset($backUrl) ? $backUrl : Request::$controller . 'browse/' . $section . '/' . (isset($parentId) ? $parentId . '/' : '')), '&larr; go back to ' . Html::chars($section))?>
<br /><br />
<table class="w100">
	<tr>
		<td class="w50 top paddingRight10" style="border-right: solid 1px #eee;">
			<table class="w100">
				<tr>
					<td>
						<?=Html::chars($name)?>
					</td>
					<td style="width: 120px;" class="right">
						<?if ($itemData['permissions']['edit']): ?>
							<?=Html::anchor(Request::$controller . 'editItem/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/edit.png" width="16" height="16" alt="Edit"/>')?>
						<?endif?>
						<?if (isset($itemData['permissions']['images']['add']) ? $itemData['permissions']['images']['add'] : false): ?>
							&nbsp;
							<?=Html::anchor(Request::$controller . 'addImage/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/images.png" width="16" height="16" alt="Add Image"/>')?>
						<?endif?>
						<?if (isset($itemData['permissions']['videos']['add']) ? $itemData['permissions']['videos']['add'] : false): ?>
							&nbsp;
							<?=Html::anchor(Request::$controller . 'addVideo/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/video.png" width="16" height="16" alt="Add Video"/>')?>
						<?endif?>
						<?if (isset($itemData['permissions']['attachments']['add']) ? $itemData['permissions']['attachments']['add'] : false): ?>
							&nbsp;
							<?=Html::anchor(Request::$controller . 'addAttachment/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/attachment.png" width="16" height="16" alt="Add Attachment"/>')?>
						<?endif?>
						<?if (isset($itemData['permissions']['audio']['add']) ? $itemData['permissions']['audio']['add'] : false): ?>
							&nbsp;
							<?=Html::anchor(Request::$controller . 'addAudio/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/audio.png" width="16" height="16" alt="Add Audio"/>')?>
						<?endif?>
						<?if ($itemData['permissions']['delete']): ?>
							&nbsp;
							<?=Html::anchor(Request::$controller . 'removeItem/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/remove.png" width="16" height="16" alt="Delete folder"/>', array('onclick' => 'javascript:return confirm(CONFIRMATION_REMOVE)'))?>
						<?endif?>
					</td>
				</tr>
				<?if (count($attachments)):?>
					<tr>
						<td colspan="2">
							<hr />
							<h3 class="dull">Attachments</h3>
						</td>
					</tr>
					<?foreach ($attachments as $attachment):?>
						<tr>
							<td>
								<?=Html::anchor('/' . $pathAttachments . $attachment['section'] . '/' . strtolower(substr($attachment['alias'], 0, 1)) . '/' . $attachment['alias'] . '/' . $attachment['filename'],
									Html::chars($attachment['name'] . ' (' . $attachment['filename'] . ')'))?>
							</td>
							<td class="right">
								<?if (
									isset($moduleSettings['attachments']['actions']['edit']) ?
									$moduleSettings['attachments']['actions']['edit'] :
									true
								):?>
									<?=Html::anchor(Request::$controller . 'editAttachment/' . $section . '/' . $attachment['id'] . '/',
										'<img src="/images/icons/small/edit.png" width="12" height="12" alt="Edit attachment"/>')?>
								<?endif?>
								<?if (
									isset($moduleSettings['attachments']['actions']['delete']) ?
									$moduleSettings['attachments']['actions']['delete'] :
									true
								):?>
									&nbsp;
									<?=Html::anchor(Request::$controller . 'removeAttachment/' . $section . '/' . $attachment['id'] . '/',
										'<img src="/images/icons/small/remove.png" width="12" height="12" alt="Remove attachment"/>')?>
								<?endif?>
							</td>
						</tr>
					<?endforeach?>
				<?endif?>
				<?if (count($audio)):?>
					<tr>
						<td colspan="2">
							<hr />
							<h3 class="dull">Audio</h3>
						</td>
					</tr>
					<?foreach ($audio as $audioItem):?>
						<tr>
							<td>
								<?=Html::anchor('/' . $pathAudio . $audioItem['section'] . '/' . strtolower(substr($audioItem['alias'], 0, 1)) . '/' . $audioItem['alias'] . '/' . $audioItem['filename'],
									Html::chars($audioItem['name'] . ' (' . $audioItem['filename'] . ')'))?>
							</td>
							<td class="right">
								<?if (
									isset($moduleSettings['audio']['actions']['edit']) ?
									$moduleSettings['audio']['actions']['edit'] :
									true
								):?>
									<?=Html::anchor(Request::$controller . 'editAudio/' . $section . '/' . $audioItem['id'] . '/',
										'<img src="/images/icons/small/edit.png" width="12" height="12" alt="Edit audio file"/>')?>
								<?endif?>
								<?if (
									isset($moduleSettings['audio']['actions']['delete']) ?
									$moduleSettings['audio']['actions']['delete'] :
									true
								):?>
									&nbsp;
									<?=Html::anchor(Request::$controller . 'removeAudio/' . $section . '/' . $audioItem['id'] . '/',
										'<img src="/images/icons/small/remove.png" width="12" height="12" alt="Remove audio file"/>')?>
								<?endif?>
							</td>
						</tr>
					<?endforeach?>
				<?endif?>
			</table>
		</td>
		<td class="w50 top paddingLeft10">
			<?if (count($images)):?>
				<?$cnt = 0;?>
				<h3 class="dull">Images</h3>
				<hr />
				<ul class="grid-sortable sortable">
					<?foreach ($images as $image):?>
						<li id="images_<?=$image['id']?>">
							<?=Html::anchor(
								Model::factory('directory')->imagePath($image, 'fullsize'),
								'<img src="' . Model::factory('directory')->imagePath($image, 'tiny') . '" width="128" height="128" alt="' . Html::chars($image['name']) . '"/>'
							)?>
							<div>
								<?if (
									isset($moduleSettings['items']['images']['sorting']) ?
									$moduleSettings['items']['images']['sorting'] :
									false
								):?>
										<span class="sortable-handler"><img src="/images/icons/16/sort4.png" width="16" height="16" /></span>
								<?endif?>
								<?if (
									isset($moduleSettings['images']['actions']['edit']) ?
									$moduleSettings['images']['actions']['edit'] :
									true
								):?>
									<?=Html::anchor(
										Request::$controller . 'editImage/' . $section . '/' . $image['id'] . '/',
										'<img src="/images/icons/16/edit.png" width="16" height="16" alt="Edit image"/>'
									)?>
								<?endif?>
								<?if (
									isset($moduleSettings['images']['actions']['delete']) ?
									$moduleSettings['images']['actions']['delete'] :
									true
								):?>
									<?=Html::anchor(
										Request::$controller . 'removeImage/' . $section . '/' . $image['id'] . '/',
										'<img src="/images/icons/16/remove.png" width="16" height="16" alt="Remove image"/>'
									)?>
								<?endif?>
								<?if ($image['hotspots']):?>
									<?=Html::anchor(
										Request::$controller . 'hotspots/' . $section . '/' . $image['id'] . '/',
										'<img src="/images/icons/16/target.png" width="16" height="16" alt="Hotspot"/>'
									)?>
								<?endif?>
							</div>
						</li>
					<?endforeach?>
				</ul>
			<?endif?>
			<?if (count($videos)):?>
				<?$cnt = 0;?>
				<h3 class="dull">Videos</h3>
				<hr />
				<table class="w100">
					<tr>
						<?foreach ($videos as $video):?>
							<td class="w25">
								<?=Html::anchor('/player/play/' . $video['section'] . '/' . $video['alias'] . '/',
									'<img src="' . $pathVideos . $video['section'] . '/preview/' . strtolower(substr($video['alias'], 0, 1)) . '/' .$video['alias'] .'_.jpg" width="100" height="75" alt="' . Html::chars($video['name']) . '"/>',
									array('rel' => '#playerOverlay')
								)?>
								<br />
								<?if (
									isset($moduleSettings['video']['actions']['edit']) ?
									$moduleSettings['video']['actions']['edit'] :
									true
								):?>
									<?=Html::anchor(Request::$controller . 'editVideo/' . $section . '/' . $video['id'] . '/',
										'<img src="/images/icons/small/edit.png" width="12" height="12" alt="Edit video details"/>')?>
								<?endif?>
								<?if (
									isset($moduleSettings['video']['actions']['delete']) ?
									$moduleSettings['video']['actions']['delete'] :
									true
								):?>
									<?=Html::anchor(Request::$controller . 'removeVideo/' . $section . '/' . $video['id'] . '/',
										'<img src="/images/icons/small/remove.png" width="12" height="12" alt="Remove video"/>')?>
								<?endif?>
								</td>
								<?$cnt++?>
								<?if ($cnt % 3 == 0):?>
									</tr><tr>
								<?endif?>
						<?endforeach?>
					</tr>
				</table>
			<?endif?>
		</td>
	</tr>
</table>
<?if (count($videos)):?>
	<div id="playerOverlay" class="videoOverlay">
		<div class="close"></div>
		<div class="contentWrap"><img src="/images/jquerytools/overlay/loading.gif" width="32" height="32" alt="Loading..." /></div>
	</div>
<?endif?>